local wangzai = fk.CreateSkill{
  name = "hanqing__wangzai",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable{
  ["hanqing__wangzai"] = "妄灾",
  [":hanqing__wangzai"] = "限定技，轮次结束时，若弃牌堆高于牌堆，你可以观看并使用牌堆底的牌直到无法使用。",

  ["#hanqing__wangzai-use"] = "妄灾：你可以使用这张牌",

  ["$hanqing__wangzai1"] = "无妄之祸，行将及矣，思恕在己，何求人兮！",
  ["$hanqing__wangzai2"] = "居无妄之世、作无妄之福，焉能无备？",
}

wangzai:addEffect(fk.RoundEnd, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(wangzai.name) and player:usedSkillTimes(wangzai.name, Player.HistoryGame) == 0 and
      #player.room.discard_pile > #player.room.draw_pile
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    while not player.dead do
      local card = room:getNCards(1, "bottom")
      if not room:askToUseRealCard(player, {
        pattern = card,
        skill_name = wangzai.name,
        prompt = "#hanqing__wangzai-use",
        extra_data = {
          bypass_times = true,
          extraUse = true,
          expand_pile = card,
        }
      }) then
        break
      end
    end
  end,
})

return wangzai
